<template>
  <div>
    <!-- <TopFilter
      :list="topFilterList"
      :cols="2"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>-->

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" slot-scope="props">
        <el-button
          size="small"
          :style="{ display: visibleCancel }"
          type="primary"
          @click="addHandle"
        >新增</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visible"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <followWaysModal :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { queryFollowWays } from '@/api/potenCus/basedata/followWays';
import { dictionary } from '@/utils/dictMixin';
import { getDataType } from '@/assets/js/auth';
import followWaysModal from './followWaysModal';
export default {
  name: 'followWays',
  mixins: [dictionary],
  components: {
    followWaysModal
  },
  data() {
    return {
      dataType: getDataType('dataType'),
      // topFilterList: this.createTopFilters(),
      fetchParams: {},
      visible: false,
      visibleCancel: '',
      dialogTitle: '',
      fetchApi: queryFollowWays,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      conf: { add: '新增', edit: '编辑' }
    };
  },
  methods: {
    createTopFilters() {},
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 60,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" disabled={this.dataType == 10461001 ? true : false} onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '跟进方式',
          dataIndex: 'basedataName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '描述',
          dataIndex: 'basedataDescribe',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '数据来源',
          dataIndex: 'dataSources',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1045'),
          render: props => {
            return <span>{this.createDictText(props.row.dataSources, '1045')}</span>;
          }
        },
        {
          title: '是否有效',
          dataIndex: 'isValid',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          }
        }
      ];
    },
    isShowData() {
      console.log('dataType', this.dataType);
      if (this.dataType != 10461001) {
        this.columns[4].hidden = true;
      } else {
        this.columns[4].hidden = false;
      }
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    showHandler() {
      this.dialogTitle = `跟进方式${this.conf[this.handleType]}`;
      this.visible = true;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({ sort: 'wayId', order: 'desc' }, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  },
  created() {
    this.isShowData();
  },
  mounted() {
    if (this.dataType == 10461001) {
      this.visibleCancel = 'none';
    }
    this.BaseTable = this.$refs.table.$refs.pageTable;
  }
};
</script>

<style lang="less" scoped>
</style>
